package com.keepercloud.qqchat.controller;

import com.alibaba.fastjson.JSONObject;
import com.keepercloud.qqchat.entity.ChatMessage;
import com.keepercloud.qqchat.framework.common.result.Result;
import com.keepercloud.qqchat.service.ChatMessageService;
import com.keepercloud.qqchat.service.UserListService;
import com.keepercloud.qqchat.util.UserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author liyk
 * @date 2019/2/12
 */
@RestController
@RequestMapping("chatMessage")
public class ChatMessageController {

    final private
    ChatMessageService chatMessageService;

    @Autowired
    public ChatMessageController( ChatMessageService chatMessageService) {
        this.chatMessageService = chatMessageService;
    }

    @GetMapping
    public Result getUserList() {
        return null;
    }

    @GetMapping("{toUsername}")
    public Result getToUsernameUserList(@PathVariable("toUsername") String toUsername, Integer page) {
        String fromUsername = UserUtil.getUserName();
        Long aLong = chatMessageService.countByFromUsernameAndToUsername(fromUsername, toUsername);
        List<Map> byFromUsernameAndToUsername = chatMessageService.findByFromUsernameAndToUsername(fromUsername, toUsername, page*20, (page+1)*20);
        return new Result(byFromUsernameAndToUsername);
    }
}
